﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.Linq;
using System.Web;
using DukeNUS.FacilitiesPlanning.FPSystem.Models;

namespace DukeNUS.FacilitiesPlanning.FPSystem.Data
{
    /// <summary>
    /// The application's entity database. Refer to the 'DBConnection' key-value-pair in the Web.config file for the  database connection string.
    /// </summary>
    public class DukeNUSDatabase : DbContext
    {

        /// <summary>
        /// Creates a new instance of the application's entity database.
        /// </summary>
        public DukeNUSDatabase()
            : base(ConfigurationManager.AppSettings["DBConnection"])
        {
            Database.SetInitializer<DukeNUSDatabase>(new DukeNUSDatabaseInitializer());
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            // Transforms each of the entity models to designated custom database table names.
            modelBuilder.Entity<User>().ToTable(ConfigurationManager.AppSettings["UsersTableName"]);
            modelBuilder.Entity<LogActivity>().ToTable(ConfigurationManager.AppSettings["LogActivitiesTableName"]);
            modelBuilder.Entity<CardReaderType>().ToTable(ConfigurationManager.AppSettings["CardReaderTypesTableName"]);
            modelBuilder.Entity<CardReaderGroup>().ToTable(ConfigurationManager.AppSettings["CardReaderGroupsTableName"]);
            modelBuilder.Entity<CardReaderDepartmentRestrictedArea>().ToTable(ConfigurationManager.AppSettings["CardReaderDeptRestrictedAreasTableName"]);
            modelBuilder.Entity<CardAccessType>().ToTable(ConfigurationManager.AppSettings["CardAccessTypesTableName"]);
            modelBuilder.Entity<CardAccessApplicantType>().ToTable(ConfigurationManager.AppSettings["CardAccessApplicantTypesTableName"]);
            modelBuilder.Entity<CardReader>().ToTable(ConfigurationManager.AppSettings["CardReadersTableName"]);
            modelBuilder.Entity<CardAccessRequest>().ToTable(ConfigurationManager.AppSettings["CardAccessRequestsTableName"]);
            modelBuilder.Entity<CardAccessRequestDetail>().ToTable(ConfigurationManager.AppSettings["CardAccessRequestDetailsTableName"]);
        }

        /// <summary>
        /// The application's entity models for the 'users' database table.
        /// </summary>
        public virtual DbSet<User> Users { get; set; }

        /// <summary>
        /// The application's entity models for the 'logactivity' database table.
        /// </summary>
        public virtual DbSet<LogActivity> LogActivities { get; set; }

        /// <summary>
        /// The application's entity models for the 'cardreaders_type' database table.
        /// </summary>
        public virtual DbSet<CardReaderType> CardReaderTypes { get; set; }

        /// <summary>
        /// The application's entity models for the 'cardreaders_group' database table.
        /// </summary>
        public virtual DbSet<CardReaderGroup> CardReaderGroups { get; set; }

        /// <summary>
        /// The application's entity models for the 'cardreadersra_dept' database table.
        /// </summary>
        public virtual DbSet<CardReaderDepartmentRestrictedArea> CardReaderDepartmentRestrictedAreas { get; set; }

        /// <summary>
        /// The application's entity models for the 'cardaccess_type' database table.
        /// </summary>
        public virtual DbSet<CardAccessType> CardAccessTypes { get; set; }

        /// <summary>
        /// The application's entity models for the 'cardaccess_applicanttype' database table.
        /// </summary>
        public virtual DbSet<CardAccessApplicantType> CardAccessApplicantTypes { get; set; }

        /// <summary>
        /// The application's entity models for the 'cardreaders' database table.
        /// </summary>
        public virtual DbSet<CardReader> CardReaders { get; set; }

        /// <summary>
        /// The application's entity models for the 'cardaccess_request' database table.
        /// </summary>
        public virtual DbSet<CardAccessRequest> CardAccessRequests { get; set; }

        /// <summary>
        /// The application's entity models for the 'cardaccess_request_details' database table.
        /// </summary>
        public virtual DbSet<CardAccessRequestDetail> CardAccessRequestDetail { get; set; }
    }
}